/*
 * @Author: EltonLi lijiaming@uavi-tech.com
 * @Date: 2023-08-31 10:16:06
 * @LastEditors: EltonLi lijiaming@uavi-tech.com
 * @LastEditTime: 2023-12-21 14:48:44
 * @FilePath: \zino-fc-v4\ZINO\sensor\LSM6DSR\lsm6dsr.h
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2023-08-31     UAVI02       the first version
 */
#ifndef __LSM6DSR_H__
#define __LSM6DSR_H__

#include <stdint.h>
#include <rtdef.h>
#include "maths.h"

#define LSM6DSR_IIC_ADDR 0XD4
#define LSM6DSR_INT1_CTRL 0X0D
#define LSM6DSR_INT2_CTRL 0X0E

#define LSM6DSR_WHO_AM_I 0X0F
#define LSM6DSR_ID 0X6B

#define LSM6DSR_CTRL1_XL 0X10
#define LSM6DSR_CTRL2_G 0X11
#define LSM6DSR_CTRL3_C 0X12
#define LSM6DSR_CTRL4_C 0X13
#define LSM6DSR_CTRL5_C 0X14
#define LSM6DSR_CTRL6_C 0X15
#define LSM6DSR_CTRL7_G 0X16
#define LSM6DSR_CTRL8_XL 0X17
#define LSM6DSR_CTRL9_XL 0X18
#define LSM6DSR_CTRL10_C 0X19

#define LSM6DSR_STATUS_REG 0X1E

#define LSM6DSR_OUT_TEMP_L 0X20
#define LSM6DSR_OUT_TEMP_H 0X21

#define LSM6DSR_OUTX_L_GYRO 0X22
#define LSM6DSR_OUTX_H_GYRO 0X23
#define LSM6DSR_OUTY_L_GYRO 0X24
#define LSM6DSR_OUTY_H_GYRO 0X25
#define LSM6DSR_OUTZ_L_GYRO 0X26
#define LSM6DSR_OUTZ_H_GYRO 0X27

#define LSM6DSR_OUTX_L_ACC 0X28
#define LSM6DSR_OUTX_H_ACC 0X29
#define LSM6DSR_OUTY_L_ACC 0X2A
#define LSM6DSR_OUTY_H_ACC 0X2B
#define LSM6DSR_OUTZ_L_ACC 0X2C
#define LSM6DSR_OUTZ_H_ACC 0X2D

#define LSM6DSR_I3C_BUS_AVB 0x62 /**These bits are used to select the bus available time when I3C IBI is used. */
#define PROPERTY_ENABLE (1U)
#define PROPERTY_DISABLE (0U)

typedef enum GYRO_LPF1
{
    GYRO_LPF1_DIS = 0 << 1,
    GYRO_LPF1_EN = 1 << 1,
} GYRO_LPF1_USE_SET_E;

typedef enum GYRO_LPF2
{
    GYRO_XL_LPF2_EN = 1<<1,
    GYRO_XL_LPF2_DIS = 0<<1,
}GYRO_LPF2_USE_SET_E;

typedef enum ACC_ODR_SET
{
    ACC_ODR_1_6HZ = 11,
    ACC_ODR_12_5HZ = 1,
    ACC_ODR_26HZ = 2,
    ACC_ODR_52HZ = 3,
    ACC_ODR_104HZ = 4,
    ACC_ODR_208HZ = 5,
    ACC_ODR_417HZ = 6,
    ACC_ODR_833HZ = 7,
    ACC_ODR_1660HZ = 8,
    ACC_ODR_3330HZ = 9,
    ACC_ODR_6660HZ = 10,
} ACC_ODR_SET_E;
typedef enum GYRO_ODR_SET
{
    GYRO_ODR_12_5HZ = 1,
    GYRO_ODR_26HZ = 2,
    GYRO_ODR_52HZ = 3,
    GYRO_ODR_104HZ = 4,
    GYRO_ODR_208HZ = 5,
    GYRO_ODR_417HZ = 6,
    GYRO_ODR_833HZ = 7,
    GYRO_ODR_1660HZ = 8,
    GYRO_ODR_3330HZ = 9,
    GYRO_ODR_6660HZ = 10
} GYRO_ODR_SET_E;

// typedef enum GYRO_LPF1_ODR_SET
// {

// }GYRO_LPF1_ODR_SET_E;

typedef enum XL_HM_MODE_SET
{
    XL_HM_MODE_ENABLE = 0 << 4, // 启用高性能模式
    XL_HM_MODE_DISABLE = 1 << 4
} XL_HM_MODE_SET_E;

typedef enum G_HM_MODE_SET
{
    G_HM_MODE_ENABLE = 0 << 7, // 启用高性能模式
    G_HM_MODE_DISABLE = 1 << 7,
} G_HM_MODE_SET_E;
typedef enum
{
    LSM6DSR_2g = 0,
    LSM6DSR_16g = 1,
    LSM6DSR_4g = 2,
    LSM6DSR_8g = 3,
} ACC_G_SET_E;
typedef enum
{
    LSM6DSR_125dps = 2,
    LSM6DSR_250dps = 0,
    LSM6DSR_500dps = 4,
    LSM6DSR_1000dps = 8,
    LSM6DSR_2000dps = 12,
    LSM6DSR_4000dps = 1,
} GYRO_DPS_SET_E;

typedef enum
{
    LSM6DSR_I3C_DISABLE = 0x80,
    LSM6DSR_I3C_ENABLE_T_50us = 0x00,
    LSM6DSR_I3C_ENABLE_T_2us = 0x01,
    LSM6DSR_I3C_ENABLE_T_1ms = 0x02,
    LSM6DSR_I3C_ENABLE_T_25ms = 0x03,
} lsm6dsr_i3c_disable_t;
typedef struct
{
    rt_uint16_t acce_range;
    rt_uint16_t gyro_range;
} range_config_t;
typedef struct
{
    struct rt_spi_device *spi_dev;
    range_config_t range;
    rt_uint8_t dev_name[8];
    rt_uint8_t dev_id;
    Axis_3_int16_t acce_raw;
    Axis_3_int16_t gyro_raw;
    Axis_3_int32_t acce;
    Axis_3_int32_t gyro;
} lsm6dsr_device_t;

typedef enum
{
    LSM6DSR_ACC_ODR_SET,
    LSM6DSR_GYRO_ODR_SET,
    LSM6DSR_ACC_RANGE_SET,
    LSM6DSR_GYRO_RANGE_SET,
    LSM6DSR_GYRO_LPF1_SET,
    LSM6DSR_LPF1_ODR_SET,
    LSM6DSR_GHM_MODE_SET,
    LSM6DSR_XLHM_MODE_SET,
} LSM6DSR_CMD_E;

// struct lsm6dsr_odr
// {
//     enum ACC_ODR_SET accodr;
//     enum GYRO_ODR_SET gyoodr;
// };

// struct lsm6dsr_range
// {
//     enum ACC_G_SET_E accrange;
//     enum GYRO_DPS_SET_E gyorange;
// };

// rt_size_t lsm6dsr_fetch_data(struct rt_sensor_device *sensor, void *buf, rt_size_t len);
// rt_size_t lsm6dsr_control(struct rt_sensor_device *sensor, int cmd, void *args);
// lsm6dsr_device_t *_lsm6dsr_init(struct rt_sensor_intf *intf);
// int16_t rt_hw_lsm6dsr_init(const char *name, struct rt_sensor_config *cfg);
#endif /* ZINO_SENSOR_LSM6DSR_LSM6DSR_H_ */
